package lookas;

import java.util.Calendar;

import lookas.model.Person;

public class PersonGenerator{
    private NamesGenerator names;
    private PeselGenerator pesels;

    public PersonGenerator(){
        names = new NamesGenerator();
        names.setProbeSize(10000);
        pesels = new PeselGenerator();
        Calendar maxYear = Calendar.getInstance();
        maxYear.add(Calendar.YEAR, -18);
        pesels.setMaxYear(maxYear);
        Calendar minYear = Calendar.getInstance();
        minYear.add(Calendar.YEAR, -90);
        pesels.setMinYear(minYear);
    }

    public Person next(){
        String im = names.nextFirstName();
        String naz = names.nextSecondName();
        int sex = im.endsWith("a") ? 0 : 1;
        if(naz.endsWith("ki") && sex == 0){
            naz = naz.replaceAll("ki$", "ka");
        }
        return new Person(im, naz, pesels.next(sex));
    }

}
